<?php

use \Cekurte\Model;

class Application_Model_User extends Model
{
	protected function setup()
	{
		$this->entity = 'User';
	}
	
	public function save( array $data, $id = null )
	{
		if( !empty( $data['password'] ) )
		{
			$data['password'] = md5( $data['password'] );
			
			return parent::save($data, $id);
		}
		
		return false;
	}
	
	public function login( $username, $password )
	{
		$registry = $this->em->getRepository( self::ENTITY_NAMESPACE . '\\' . $this->entity )->findBy( array(
			'username' 	=> $username,
			'password'	=> md5( $password )
		));
		
		return empty( $registry ) ? false : $registry[0];
	}
}